package com.gome.ocean.service.datax.impl;

import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.gome.ocean.common.exception.JobHistoryServiceException;
import com.gome.ocean.dao.datax.JobHistoryDAO;
import com.gome.ocean.dao.model.datax.JobHistoryBO;
import com.gome.ocean.service.datax.JobHistoryService;

@Service
@Transactional("transactionManager")
public class JobHistoryServiceImpl implements JobHistoryService {

    private final Logger  LOG = LoggerFactory.getLogger(JobHistoryServiceImpl.class);
    @Autowired
    private JobHistoryDAO jobHistoryDAO;

    @Override
    public void insertJobHistory(JobHistoryBO jobHistoryBO) {
        jobHistoryDAO.insertJobHistory(jobHistoryBO);
    }

    @Override
    public void removeJobHistoryById(Long id) {
        jobHistoryDAO.removeJobHistoryById(id);
    }

    @Override
    public void updateJobHistoryById(JobHistoryBO jobHistoryBO) {
        jobHistoryDAO.updateJobHistoryById(jobHistoryBO);
    }

    @Override
    public JobHistoryBO findJobHistoryById(Long id) {
        return jobHistoryDAO.findJobHistoryById(id);
    }

    @Override
    public Page<JobHistoryBO> findJobHistoryByJobId(Long jobId, int pageNum,
                                                    int pageSize) throws JobHistoryServiceException {
        Page<JobHistoryBO> jobHistoryBOs = null;
        try {
            jobHistoryBOs = (Page) jobHistoryDAO.findJobHistoryByJobId(jobId, new RowBounds(pageNum, pageSize));
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            return null;
        }
        return jobHistoryBOs;
    }

    @Override
    public JobHistoryBO findCurrentJob(Long id) {
        return jobHistoryDAO.findCurrentJob(id);
    }

}
